package com.cogent.business.action.base;

import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import com.cogent.business.action.AbstractAction;
import com.cogent.business.domain.UserDomain;
import com.cogent.business.helper.DistrictHelper;
import com.cogent.common.util.MapUtil;

public class OpenApiAction extends AbstractAction {
	
	public String getsubOption() {
		UserDomain userdomain = getUserInfo();
		if(userdomain == null)
			return null;
		HashMap formMap = getFormMapWithUser();
		int islimit = MapUtil.getIntValue(formMap, "islimit");
		List list = DistrictHelper.getSubDistOptionList(formMap, MapUtil.getStringValue(formMap, "parentid"), "", false);
		String message = MapUtil.listMapToJsonStr(list);
		responseMsg(message);
		
		return null;
	}
	
	public String getsubOptionXml() {
		UserDomain userdomain = getUserInfo();
		if(userdomain == null)
			return null;
		HashMap formMap = getFormMapWithUser();
		int islimit = MapUtil.getIntValue(formMap, "islimit");
		String curvalue = MapUtil.getStringValue(formMap, "curvalue");
		List list = DistrictHelper.getSubDistOptionList(formMap, MapUtil.getStringValue(formMap, "parentid"), "", false);
		StringBuffer str = new StringBuffer();
		str.append("<option value=\"\">请选择</option>");
		Iterator it = list.iterator();
		while(it.hasNext()) {
			HashMap dataMap = (HashMap)it.next();
			str.append("<option value=\"").append(MapUtil.getStringValue(dataMap, "value")).append("\"");
			if(curvalue.equals(MapUtil.getStringValue(dataMap, "value")))
				str.append(" selected=\"selected\"");
			str.append(">").append(MapUtil.getStringValue(dataMap, "option")).append("</option>");
		}
		Map curMap = new HashMap();
		curMap.put("optionxml", str.toString());
		String message = MapUtil.mapToJsonStr(curMap);
		responseMsg(message);
		
		return null;
	}
}
